<?php 
/* this file will delete basket item */
// load wordpress defaults, make global variables/functions available
$this_file = str_replace( '\\', '/', __FILE__ );
$this_file = explode( 'wp-content', $this_file );
$this_file = $this_file[ 0 ];
require( $this_file . 'wp-blog-header.php' );
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<!-- head start -->

<head profile="http://gmpg.org/xfn/11">
	<?php
    $aOptions = SofaSuppaStore::initOptions( false );
	$entrycurrency = $aOptions[ 'entrycurrency' ];
	// handle font selection
	$google_fonts = $aOptions[ 'google_fonts' ];
	$font_str = $google_fonts;
	$font_str_arr = explode( ':', $font_str );
	$font_name = $font_str_arr[ 0 ];
	$clean_font_arr = explode( '+', $font_name );
	$clean_font_name = implode( ' ', $clean_font_arr );
    ?>
    <link href='http://fonts.googleapis.com/css?family=<?php echo $google_fonts; ?>' rel='stylesheet' type='text/css' />
    <link rel="stylesheet" href="<?php echo( get_template_directory_uri() . '/960.css' ); ?>" type="text/css" media="screen, projection" />
    <link rel="stylesheet" href="<?php echo( get_template_directory_uri() . '/screen.css' ); ?>" type="text/css" media="screen, projection" />
    <style type="text/css">
	/* handle basic styles according to google fonts selection */
	h1, h2, h3, h4, h5, h6 { font-family: '<?php echo $clean_font_name; ?>', Arial, sans-serif; font-weight: normal; }
	</style>
	<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" type="text/css" media="screen, projection" />
    
    <?php wp_print_scripts( 'jquery' ); ?>
    <script src="<?php echo( get_template_directory_uri() . '/script/jquery.suppastore.custom.js' ); ?>" type="text/javascript"></script>

</head>

<!-- head end -->

<body>

<!-- main content start -->

<div id="lightcontent" class="container_8 clearfix">
    
	<?php
	// get item details
	if( $_SERVER[ 'REQUEST_METHOD' ] == 'GET' ) {
		$itemid    = !empty( $_GET[ 'itemid' ] ) ? intval( urldecode( $_GET[ 'itemid' ] ) ) : NULL; // product id
		$itemsize  = !empty( $_GET[ 'itemsize' ] ) ? stripslashes( strip_tags( urldecode( $_GET[ 'itemsize' ] ) ) ) : NULL; // product size
		$cookid    = !empty( $_GET[ 'cookid' ] ) ? stripslashes( strip_tags( urldecode( $_GET[ 'cookid' ] ) ) ) : NULL; // cookie id
		$itemqty   = !empty( $_GET[ 'itemqty' ] ) ? intval( urldecode( $_GET[ 'itemqty' ] ) ) : NULL; // quantity
		$itemstock = !empty( $_GET[ 'itemstock' ] ) ? intval( urldecode( $_GET[ 'itemstock' ] ) ) : NULL; // in stock
		$itemprice = !empty( $_GET[ 'itemprice' ] ) ? floatval( urldecode( $_GET[ 'itemprice' ] ) ) : NULL; // price
		$itemshipp = !empty( $_GET[ 'itemshipp' ] ) ? floatval( urldecode( $_GET[ 'itemshipp' ] ) ) : NULL; // individual shipping price
	} elseif( $_SERVER[ 'REQUEST_METHOD' ] == 'REQUEST' ) {
		$itemid    = !empty( $_REQUEST[ 'itemid' ] ) ? intval( urldecode( $_REQUEST[ 'itemid' ] ) ) : NULL; // product id
		$itemsize  = !empty( $_REQUEST[ 'itemsize' ] ) ? stripslashes( strip_tags( urldecode( $_REQUEST[ 'itemsize' ] ) ) ) : NULL; // product size
		$cookid    = !empty( $_REQUEST[ 'cookid' ] ) ? stripslashes( strip_tags( urldecode( $_REQUEST[ 'cookid' ] ) ) ) : NULL; // cookie id
		$itemqty   = !empty( $_REQUEST[ 'itemqty' ] ) ? intval( urldecode( $_REQUEST[ 'itemqty' ] ) ) : NULL; // quantity
		$itemstock = !empty( $_REQUEST[ 'itemstock' ] ) ? intval( urldecode( $_REQUEST[ 'itemstock' ] ) ) : NULL; // in stock
		$itemprice = !empty( $_REQUEST[ 'itemprice' ] ) ? floatval( urldecode( $_REQUEST[ 'itemprice' ] ) ) : NULL; // price
		$itemshipp = !empty( $_REQUEST[ 'itemshipp' ] ) ? floatval( urldecode( $_REQUEST[ 'itemshipp' ] ) ) : NULL; // individual shipping price
	}

	// get the post
	$post_obj = get_post( $itemid );
	?>

    <div id="featured" class="castshadow grid_8">
    
    	<!-- title start -->
    
       	<h2 class="grid_8 alpha omega"><?php _e( "REMOVE", "sofa_suppastore" ); ?> <?php echo get_the_title( $post_obj->ID ); ?></h2>
        
        <!-- title end -->
        
        <!-- product image start -->
        
        <div id="prodimageset" class="grid_2 alpha">
        
        	<?php
			echo '<div class="grid_2 alpha omega">';
			$img_attr = array( 'class'	=> 'size-thumbnail alignleft topzero' );
			echo get_the_post_thumbnail( $post_obj->ID, 'thumbnail', $img_attr );
			echo '</div>';
			?>
        
        </div>
        
        <!-- product image end -->
        
        <!-- product in basket details start -->
        
        <div id="proddetails" class="grid_6 omega">
        
        	<table id="tblmeta" width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <th scope="col" class="textleft"><?php _e( "Size", "sofa_suppastore" ); ?></th>
                <th scope="col" class="center"><?php echo __( "Price", "sofa_suppastore" ) . ' ' . '(' . $entrycurrency . ')'; ?></th>
                <?php if( $itemshipp != '' ) { ?><th scope="col" class="center"><?php echo __( "Shipping", "sofa_suppastore" ) . ' ' . '(' . $entrycurrency . ')'; ?></th><?php } ?>
                <th scope="col" class="textright"><?php echo __( "Item(s) Total", "sofa_suppastore" ) . ' ' . '(' . $entrycurrency . ')'; ?></th>
              </tr>
              
              <?php
			  	$items_ship_total = 0;
				$items_total = $itemqty * $itemprice;
				if( $itemshipp != '' ) $items_ship_total = $itemqty * $itemshipp;
				echo '<tr id="infoline_1" class="proddetailstr">';
				echo '<td title="size" class="optionactiv textleft">' . $itemsize . '</td>';
				echo '<td title="price" class="center">' . number_format( $itemprice, 2, '.', '' ) . '</td>';
				if( $itemshipp != '' ) echo '<td title="shipp" class="center">' . number_format( $items_ship_total, 2, '.', '' ) . '</td>';
				echo '<td title="total" class="textright">' . number_format( $items_total, 2, '.', '' ) . '</td>';
				echo '</tr>';
			  ?>
              
            </table>
            
            <form id="buyme" method="post" action="<?php echo get_template_directory_uri() . '/cart_handler.php'; ?>">
            
                <div class="grid_6 alpha omega">
                
                    <div class="left"><span class="qty"><?php _e( "Quantity", "sofa_suppastore" ); ?></span>: <span id="spanitemqty">&nbsp;</span></div>
                    <div class="right"><button type="submit" tabindex="2"><?php _e( "Remove from Basket", "sofa_suppastore" ); ?></button></div>
                    
                </div>
                
                <input type="hidden" name="itemid" id="itemid" value="<?php echo $post_obj->ID; ?>" />
                <input type="hidden" name="dothis" id="dothis" value="delme" />
                <input type="hidden" name="itemsize" id="itemsize" value="" />
                <input type="hidden" name="itemprice" id="itemprice" value="" />
                <input type="hidden" name="itemstock" id="itemstock" value="" />
                <input type="hidden" name="cookid" id="cookid" value="<?php echo $cookid; ?>" />
                <?php wp_nonce_field( 'chck_ref_cc', 'sofa_suppastore_cc' ); ?>
            
            </form>
        
        </div>
        
        <!-- product in basket details end -->
        
        <script type="text/javascript">
        
        jQuery( document ).ready( function() {
            
            // populate fields
			jQuery( '#itemsize' ).val( "<?php echo $itemsize; ?>" );
			jQuery( '#itemprice' ).val( "<?php echo $itemprice; ?>" );
			jQuery( '#itemstock' ).val( "<?php echo $itemstock; ?>" );
			jQuery( '#spanitemqty' ).text( "<?php echo $itemqty; ?>" );
			
            var written_price = jQuery( '#itemprice' ).val();
            if( written_price != '' ) jQuery( '#prodprice' ).html( "<?php echo $entrycurrency . ' '; ?>" + number_format( written_price, 2, '.', '' ) );
        } );
		
		// format number
		function number_format( number, decimals, dec_point, thousands_sep ) {
			number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
			var n = !isFinite(+number) ? 0 : +number,
			prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
			sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
			dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
			s = '',
			toFixedFix = function (n, prec) {
				var k = Math.pow(10, prec);
				return '' + Math.round(n * k) / k;
			};
			// Fix for IE parseFloat(0.55).toFixed(0) = 0;
			s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
			if (s[0].length > 3) {
				s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
			}
			if ((s[1] || '').length < prec) {
				s[1] = s[1] || '';
				s[1] += new Array(prec - s[1].length + 1).join('0');
			}
			return s.join(dec);
		}
        
        </script>
        
    </div>
        
</div>

<!-- main content end -->

</body>
</html>